package com.tz.fruit.entity;

import java.io.Serializable;

import javax.persistence.*;

/**
* 购物车实体类
*/
@Entity
@Table(name="FRUIT_CART")
public class Cart implements Serializable{
	private Long cartId;//购物车ID

	private double total; //总费用
	private int count; //商品总数量

	private User user;//购物车所属用户

	public Cart() {
	}

	public Cart(double total, int count, User user) {
		super();
		this.total = total;
		this.count = count;
		this.user = user;
	}
	@Id
	@GeneratedValue
	public Long getCartId() {
		return cartId;
	}

	public void setCartId(Long cartId) {
		this.cartId = cartId;
	}

	public double getTotal() {
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}
	@OneToOne
	@JoinColumn(name="userId")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cartId == null) ? 0 : cartId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Cart other = (Cart) obj;
		if (cartId == null) {
			if (other.cartId != null)
				return false;
		} else if (!cartId.equals(other.cartId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Cart [cartId=" + cartId + ", total=" + total + ", count=" + count + "]";
	}
	
}
